﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Linq;
using System.Text;
using System.Web;

namespace ContractorTimesheet.Repository
{
    public class BaseRepository
    {
        protected string GetErrorMessage(DbEntityValidationException ex)
        {
            StringBuilder builder = new StringBuilder();

            foreach (var failure in ex.EntityValidationErrors)
            {
                builder.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());

                foreach (var error in failure.ValidationErrors)
                {
                    builder.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                    builder.AppendLine();
                }
            }

            return builder.ToString();
        }
    }
}
